home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / seyon / SeSubsX.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  293 lines

  1.  
  2. /*
  3.  * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
  4.  * Saggaf. All rights reserved.
  5.  *
  6.  * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
  7.  * statement of rights and permissions for this program.
  8.  */
  9.  
  10. #include <time.h>
  11.  
  12. #include <X11/Intrinsic.h>
  13. #include <X11/StringDefs.h>
  14.  
  15. #include "seyon.h"
  16. #include "SeDecl.h"
  17.  
  18. extern char    *strsqtok();
  19. extern int      GetModemStat();
  20.  
  21. int             seyon_message_up = 0;
  22.  
  23. void
  24. UpdateStatusBox(clientData)
  25.      XtPointer       clientData;
  26. {
  27.   static Widget *statusWidget;
  28.   /* All members of oldState are guaranteed to be initialized to False
  29.      since the array is declared static, similarly for online */
  30.   static Boolean online, oldState[NUM_MDM_STAT];
  31.   Boolean newState;
  32.   char buf[10];
  33.   static int stat[NUM_MDM_STAT] = {MDM_DCD, MDM_DTR, MDM_DSR, MDM_RTS, 
  34.                                      MDM_CTS, MDM_RNG};
  35.   int modemStat, i;
  36.   static time_t startTime, oldOnlineTime = 0;
  37.   time_t onlineTime = 0;
  38.  
  39.   if (clientData)
  40.     statusWidget = (Widget*)clientData;
  41.  
  42.   if ((modemStat = GetModemStat(0)) >= 0)
  43.     for (i = 0; i < 6; i++)
  44.       if ((newState = (Boolean)((modemStat & stat[i]) ? True : False)) != 
  45.           oldState[i])
  46.         SeSetUnsetToggle(statusWidget[i], (oldState[i] = newState));
  47.   
  48.   if (online == False) {
  49.     onlineTime = 0;
  50.     startTime = time((time_t*)0);
  51.   }
  52.   if ((online = oldState[0]))
  53.     onlineTime = (time((time_t*)0) - startTime) / 60;
  54.  
  55.   if (onlineTime != oldOnlineTime) {
  56.     oldOnlineTime = onlineTime;
  57.     sprintf(buf, "%02d:%02d", onlineTime / 60, onlineTime % 60);
  58.     SeSetLabel(statusWidget[0], buf);
  59.   }
  60.  
  61.   if (clientData)
  62.     XtAppAddTimeOut(app_con, qres.modemStatusInterval * 1000, 
  63.                     UpdateStatusBox, clientData);
  64. }
  65.  
  66. void
  67. FunMessage()
  68. {
  69.   static int      msg_index = 0;
  70.   String          msg;
  71.   char            vermsg[SM_BUF];
  72.  
  73.   if (seyon_message_up <= 0) {
  74.  
  75.     msg = qres.funMessages[msg_index++];
  76.     if (msg == NULL) {
  77.       msg_index = 0;
  78.       sprintf(vermsg, "Welcome to Seyon version %s%s", VERSION, REVISION);
  79.       msg = vermsg;
  80.     }
  81.  
  82.     SetStatusMessage(msg);
  83.   }
  84.  
  85.   seyon_message_up--;
  86.  
  87.   XtAppAddTimeOut(XtWidgetToApplicationContext(topLevel),
  88.                   qres.funMessagesInterval * 1000, FunMessage, NULL);
  89. }
  90.  
  91. struct _procRequest {
  92.   int             action;
  93.   char            msg[80];
  94.   char            arg[90];
  95. };
  96.  
  97. void
  98. ExecProcRequest(client_data)
  99.      XtPointer       client_data;
  100. {
  101.   void                DispatchActions(),
  102.                       RunScript();
  103.   struct _procRequest procRequest;
  104.  
  105.   read_pipe_data(child_pipe, &procRequest, sizeof(procRequest));
  106.  
  107.   if (*(procRequest.msg))
  108.     SeyonMessage(procRequest.msg);
  109.  
  110.   switch (procRequest.action) {
  111.   case KILL_TERM:
  112.     KillTerminal();
  113.     break;
  114.   case START_TERM:
  115.     StartTerminal();
  116.     break;
  117.   case SUSPEND_TERM:
  118.     SuspContTerminal(0);
  119.     break;
  120.   case CONTINUE_TERM:
  121.     SuspContTerminal(1);
  122.     break;
  123.   case DISPATCH_ACTION:
  124.     DispatchActions(ACTION_DISPATCH, procRequest.arg, genericWidget);
  125.     break;
  126.   case EXEC_SCRIPT:
  127.     RunScript(NULL, procRequest.arg);
  128.     break;
  129.   case TOP_DIAL_START:
  130.     qres.dialAutoStart = True;
  131.   case TOP_DIAL:
  132.     if ((procRequest.arg)[0]) TopDial(dialWidget, procRequest.arg);
  133.     else TopDial(dialWidget, NULL);
  134.     break;
  135.   case POPUP_ERROR:
  136.     PopupError(procRequest.arg, NULL);
  137.     break;
  138.   case EXIT_PROGRAM:
  139.     s_exit();
  140.     break;
  141.   case SET_MESSAGE:
  142.     break;
  143.   default:
  144.     break;
  145.   }
  146. }
  147.  
  148. void
  149. write_child_info(pd, action, msg)
  150.      int            *pd;
  151.      int             action;
  152.      char           *msg;
  153. {
  154.   struct _procRequest procRequest;
  155.  
  156.   procRequest.action = action;
  157.  
  158.   if (msg) strcpy(procRequest.msg, msg);
  159.   else *procRequest.msg = '\0';
  160.  
  161.   write_pipe_data(pd, &procRequest, sizeof(procRequest));
  162. }
  163.  
  164. void
  165. ProcRequest(action, msg, arg)
  166.      int             action;
  167.      char           *msg,
  168.                     *arg;
  169. {
  170.   struct _procRequest procRequest;
  171.  
  172.   procRequest.action = action;
  173.   strcpy(procRequest.msg, msg);
  174.   strcpy(procRequest.arg, arg);
  175.  
  176.   write_pipe_data(child_pipe, &procRequest, sizeof(procRequest));
  177. }
  178.  
  179. void
  180. writef_child_info(pd, action, fmt, a, b, c)
  181.      int            *pd;
  182.      int             action;
  183.      char           *fmt,
  184.                     *a,
  185.                     *b,
  186.                     *c;
  187. {
  188.   char            buffer[SM_BUF];
  189.  
  190.   sprintf(buffer, fmt, a, b, c);
  191.   write_child_info(pd, action, buffer);
  192. }
  193.  
  194. void
  195. SeyonMessage(msg)
  196.      String          msg;
  197. {
  198.   seyon_message_up = 300 / qres.funMessagesInterval;
  199.   SetStatusMessagef("- %s -", msg, "", "");
  200. }
  201.  
  202. void
  203. SeyonMessagef(fmt, a, b, c)
  204.      String          fmt,
  205.                      a,
  206.                      b,
  207.                      c;
  208. {
  209.   char            buf[REG_BUF];
  210.  
  211.   sprintf(buf, fmt, a, b, c);
  212.   SeyonMessage(buf);
  213. }
  214.  
  215. Boolean
  216. read_seyon_file(name, line)
  217.      char           *name,
  218.                     *line[];
  219. {
  220.   FILE           *fp;
  221.  
  222.   if ((fp = open_file(name, qres.defaultDirectory)) == NULL)
  223.     return False;
  224.  
  225.   ReadCommentedFile(fp, line);
  226.   fclose(fp);
  227.  
  228.   return True;
  229. }
  230.  
  231. #define done(value, type) \
  232. { \
  233.   if (toVal->addr != NULL) { \
  234.     if (toVal->size < sizeof(type)) { \
  235.       toVal->size = sizeof(type); \
  236.       return False; \
  237.     } \
  238.     *(type*)(toVal->addr) = (value); \
  239.   } \
  240.   else { \
  241.     static type static_val; \
  242.     static_val = (value); \
  243.     toVal->addr = (XtPointer)&static_val; \
  244.   } \
  245.   toVal->size = sizeof(type); \
  246.   return True; \
  247. }
  248.  
  249. Boolean
  250. CvtStringToStringArray(display, args, num_args, fromVal, toVal,
  251.                converter_data)
  252.      Display        *display;
  253.      XrmValue       *args;
  254.      Cardinal       *num_args;
  255.      XrmValue       *fromVal;
  256.      XrmValue       *toVal;
  257.      XtPointer      *converter_data;
  258. {
  259.   String          fromStr,
  260.                   buf;
  261.   static String   strArr[REG_BUF];
  262.   int             n;
  263.  
  264.   if (*num_args != 0)
  265.     XtAppWarningMsg(app_con, "wrongParameters", "cvtStringToStringArray",
  266.             "XtToolkitError",
  267.         "String to StringArray conversion needs no extra arguments",
  268.             (String *) NULL, (Cardinal *) NULL);
  269.  
  270.   fromStr = (String) fromVal->addr;
  271. /*  buf = XtMalloc((strlen(fromStr)+1) * sizeof(char));
  272.   strcpy(buf, fromStr);*/
  273.   buf = fromStr;
  274.  
  275.   if ((strArr[0] = strsqtok(buf)) == NULL) {
  276. /*    XtFree(buf);*/
  277.     done(NULL, String *);
  278.   }
  279.  
  280.   for (n = 1; n < XtNumber(strArr); n++)
  281.     if ((strArr[n] = strsqtok(NULL)) == NULL)
  282.       done(strArr, String *);
  283.  
  284.   XtAppWarningMsg(app_con, "tooManyStrings", "cvtStringToStringArray",
  285.           "XtToolkitError",
  286.        "Too many strings specified for String to StringArray converter",
  287.           (String *) NULL, (Cardinal *) NULL);
  288.   strArr[--n] = NULL;
  289.   done(strArr, String *);
  290. }
  291.  
  292. #undef done
  293.